package com.company.indicationshots.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.SimpleAdapter;

import com.company.indicationshots.R;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

//当前射击成绩列表适配器
public class CurrListAdapter extends SimpleAdapter {

    private Context context;
    private List<Map<String, Object>> data;
    private int layoutResource;
    private String[] from;
    private int[] to;

    public CurrListAdapter(Context context, List<Map<String, Object>> data, int layoutResource, String[] from, int[] to) {
        super(context, data, layoutResource, from, to);
        this.context = context;
        this.data = data;
        this.layoutResource = layoutResource;
        this.from = from;
        this.to = to;
    }

    // 添加一行数据到适配器中
    public void addRow(Map<String, Object> row) {
        data.add(row);
        // 通知适配器数据已经改变
        notifyDataSetChanged();
    }

    //加载射击数据
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = super.getView(position, convertView, parent);
        Map<String, Object> map = (Map<String, Object>) getItem(position);
        String pos = (String) map.get("curr_list_position");
        ImageView currListPosition = view.findViewById(R.id.curr_list_position);
        switch (pos) {
            case "上":
                currListPosition.setImageResource(R.drawable.up);
                break;
            case "下":
                currListPosition.setImageResource(R.drawable.down);
                break;
            case "左":
                currListPosition.setImageResource(R.drawable.left);
                break;
            case "右":
                currListPosition.setImageResource(R.drawable.right);
                break;
            case "左上":
                currListPosition.setImageResource(R.drawable.upleft);
                break;
            case "左下":
                currListPosition.setImageResource(R.drawable.lowleft);
                break;
            case "右上":
                currListPosition.setImageResource(R.drawable.upright);
                break;
            case "右下":
                currListPosition.setImageResource(R.drawable.lowright);
                break;
        }
        return view;
    }

}
